//Grozi Ties
// David Ing and Jae Shin Woo
//
// Grozi.SendA.ck
// This is a program that sends OSC packets to port 7000.  It is
// meant to simulate the data sent to us by the User Interface
// team
//
// This program is based off of the code from the TIES team of
// Fall 2010
//----------------------------------------------------------------

"localhost" => string hostname; 
7000 => int port;  // port that it sends to

// sends packet
if( me.args() ) me.arg(0) => hostname;
if( me.args() > 1 ) me.arg(1) => Std.atoi => port;
OscSend xmit;

1 => int mouseDelta;

// sets the hose name at the given port
xmit.setHost( hostname, port );
Hid hi; 
0 => int cont;
0 => int a;
HidMsg msg;
0 => int device; 

// Activates mouse
if( me.args() ) me.arg(0) => Std.atoi => device;
if( !hi.openMouse( device ) ) me.exit();
0 => int Xpos;

// loops thorugh while packets are being sent
while( true ){
  hi => now;
  
  while( hi.recv( msg ) ){
    // updates x position
    Xpos + msg.deltaX => Xpos;
    if( msg.isButtonDown() ){
      // compensates for the button click
      Xpos - mouseDelta => Xpos;
      
      if( msg.deltaX ){
        // Sends Xposition
        <<< "SENDING: ", Xpos  >>>;
        xmit.startMsg( "/edge", "i" );
        cont + 1 => cont;
        // Sends packet to specified port
        if(cont==1){
          0 => cont;
          <<<"SSS">>>; 
          (Xpos/10) =>xmit.addInt; 
        } 
      }
    }
  }
}

